﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.FactoryUI {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import Events.*;
    import flash.utils.*;
    import org.aswing.*;
    import Classes.*;
    import org.aswing.geom.*;
    import Display.*;
    import org.aswing.border.*;
    import com.zynga.skelly.util.color.*;
    import Display.aswingui.*;
    import Display.MarketUI.assets.*;

    public class SuppliesCell extends DataItemCell {

        private var m_amountNeeded:int;
        private var m_itemCost:JLabel;
        private var m_bgDec:MarginBackground;
        protected var m_currencyIcon:JPanel;
        protected var m_alignmentContainer:JPanel;
        protected var m_itemIconPane:JPanel;
        protected var m_content:DisplayObject;
        protected var m_bgOver:DisplayObject;
        protected var m_swappedBG:DisplayObject;
        protected var m_itemLocked:Boolean;
        protected var m_curBGAsset:DisplayObject;
        protected var m_containerWidth:int;
        protected var m_containerHeight:int;
        protected var m_itemIconHolder:JPanel;

        public function SuppliesCell(_arg1:LayoutManager=null){
            super(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, 0, SoftBoxLayout.CENTER));
        }
        override public function setCellValue(_arg1):void{
            _arg1 = (_arg1 as Object);
            m_item = _arg1;
            this.m_amountNeeded = m_item.cost;
            var _local2:String = Global.gameSettings.getImageByName(m_item.name, "icon");
            m_loader = LoadingManager.load(_local2, onIconLoad, LoadingManager.PRIORITY_HIGH);
            this.buildCell();
        }
        protected function buildCell():void{
            this.m_alignmentContainer = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP);
            if (m_item.unlock == "level"){
                if (Global.player.level < m_item.requiredLevel){
                    this.m_itemLocked = true;
                } else {
                    this.m_itemLocked = false;
                };
            } else {
                if (m_item.unlock == "neighbors"){
                };
            };
            this.m_content = (this.m_itemLocked) ? (new (SuppliesDialog.assetDict["supplies_lockedcard"])() as DisplayObject) : (new (SuppliesDialog.assetDict["supplies_card"])() as DisplayObject);
            this.setPreferredWidth((this.m_content.width + 2));
            this.setMinimumWidth((this.m_content.width + 2));
            this.setMaximumWidth((this.m_content.width + 2));
            this.m_bgDec = new MarginBackground(this.m_content, new Insets(0, 0, 0, 0));
            this.m_alignmentContainer.setBackgroundDecorator(this.m_bgDec);
            this.m_alignmentContainer.setPreferredSize(new IntDimension(this.m_content.width, this.m_content.height));
            this.m_alignmentContainer.setMinimumSize(new IntDimension(this.m_content.width, this.m_content.height));
            this.m_alignmentContainer.setMaximumSize(new IntDimension(this.m_content.width, this.m_content.height));
            ASwingHelper.prepare(this);
            var _local1:JLabel = new JLabel(m_item.localizedName);
            _local1.setForeground(new ASColor(EmbeddedArt.brownTextColor, 1));
            if (this.m_itemLocked){
                _local1.setForeground(new ASColor(0x8A8A8A, 1));
            } else {
                _local1.setForeground(new ASColor(EmbeddedArt.brownTextColor, 1));
            };
            _local1.setFont(ASwingHelper.getBoldFont(18));
            this.m_alignmentContainer.append(_local1);
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local3:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP);
            var _local4:JPanel = (this.m_itemLocked) ? this.makeLockedRightSide() : this.makeNormalRightSide();
            var _local5:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT);
            var _local6:JLabel = new JLabel(ZLoc.t("Dialogs", "FactoryCosts"));
            _local6.setFont(ASwingHelper.getStandardFont(14));
            if (this.m_itemLocked){
                _local6.setForeground(new ASColor(0x595959, 1));
            } else {
                _local6.setForeground(new ASColor(EmbeddedArt.brownTextColor, 1));
            };
            _local5.append(_local6);
            var _local7:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local8:JLabel = new JLabel(String(m_item.cost));
            _local8.setFont(ASwingHelper.getBoldFont(18));
            if (this.m_itemLocked){
                _local8.setForeground(new ASColor(0x8A8A8A, 1));
            } else {
                _local8.setForeground(new ASColor(11737883, 1));
            };
            var _local9:AssetPane = new AssetPane((new (SuppliesDialog.assetDict["coin_small"])() as DisplayObject));
            _local7.appendAll(_local9, _local8);
            _local3.appendAll(_local5, _local7);
            _local2.appendAll(_local3, ASwingHelper.horizontalStrut(15), _local4);
            this.m_alignmentContainer.append(_local2);
            this.m_itemIconHolder = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local10:DisplayObject = (new (SuppliesDialog.assetDict["icon_bg"])() as DisplayObject);
            this.m_itemIconHolder.setBackgroundDecorator(new AssetBackground(_local10));
            this.m_containerWidth = _local10.width;
            this.m_containerHeight = _local10.height;
            ASwingHelper.prepare(this.m_itemIconHolder);
            _local3.appendAll(ASwingHelper.verticalStrut(15), this.m_itemIconHolder);
            ASwingHelper.prepare(this.m_alignmentContainer);
            ASwingHelper.prepare(_local2);
            this.m_alignmentContainer.append(_local2);
            if (!this.m_itemLocked){
                this.addEventListener(MouseEvent.CLICK, this.buyItem, false, 0, true);
                this.addEventListener(MouseEvent.ROLL_OVER, this.rollOverItem, false, 0, true);
                this.addEventListener(MouseEvent.ROLL_OUT, this.rollOutItem, false, 0, true);
            };
            this.append(this.m_alignmentContainer);
            ASwingHelper.prepare(this);
        }
        private function rollOverItem(_arg1:MouseEvent):void{
            var _local2:ColorMatrix = new ColorMatrix();
            _local2.adjustContrast(0.3, 0.3, 0.3);
            this.filters = [_local2.filter];
        }
        private function rollOutItem(_arg1:MouseEvent):void{
            this.filters = [];
        }
        private function makeLockedRightSide():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local2:DisplayObject = (new (SuppliesDialog.assetDict["lock_bg"])() as DisplayObject);
            _local1.setBackgroundDecorator(new AssetBackground(_local2));
            _local1.setMaximumSize(new IntDimension(_local2.width, _local2.height));
            _local1.setMinimumSize(new IntDimension(_local2.width, _local2.height));
            var _local3:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER, -3);
            _local3.setBorder(new EmptyBorder(null, new Insets(0, 10, 0, 10)));
            _local1.append(_local3);
            var _local4:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER, -6);
            var _local5:DisplayObject = (new (SuppliesDialog.assetDict["slot_locked"])() as DisplayObject);
            _local4.setBackgroundDecorator(new AssetBackground(_local5));
            var _local6:JLabel = new JLabel(ZLoc.t("Dialogs", "FactoryRequires"));
            _local6.setFont(ASwingHelper.getStandardFont(13));
            _local6.setForeground(ASwingHelper.getWhite());
            var _local7:JLabel = new JLabel(ZLoc.t("Dialogs", "FactoryLevel", {level:String(m_item.requiredLevel)}));
            _local7.setFont(ASwingHelper.getBoldFont(15));
            _local7.setForeground(ASwingHelper.getWhite());
            _local4.appendAll(_local6, _local7);
            var _local8:JLabel = new JLabel(ZLoc.t("Dialogs", "FactoryOr"));
            _local8.setFont(ASwingHelper.getBoldFont(16));
            _local8.setForeground(new ASColor(0x8A8A8A, 1));
            var _local9:JLabel = new JLabel(ZLoc.t("Dialogs", "FactoryEarly"));
            _local9.setFont(ASwingHelper.getStandardFont(14));
            _local9.setForeground(new ASColor(23188, 1));
            var _local10:CustomButton = new CustomButton(String(m_item.cash), (new (SuppliesDialog.assetDict["cash"])() as Icon), "BuyGateKeyButtonUI");
            _local3.appendAll(ASwingHelper.verticalStrut(35), _local4, _local8, _local9, _local10, ASwingHelper.verticalStrut(10));
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        private function makeNormalRightSide():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP, 5);
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT);
            var _local3:JLabel = new JLabel(ZLoc.t("Dialogs", "FactoryEarns"));
            _local3.setFont(ASwingHelper.getStandardFont(14));
            _local3.setForeground(new ASColor(EmbeddedArt.brownTextColor, 1));
            _local2.append(_local3);
            var _local4:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local5:JLabel = new JLabel(String(m_item.coinYield));
            _local5.setFont(ASwingHelper.getBoldFont(26));
            _local5.setForeground(new ASColor(EmbeddedArt.brownTextColor, 1));
            var _local6:AssetPane = new AssetPane((new (SuppliesDialog.assetDict["coin_big"])() as DisplayObject));
            _local4.appendAll(_local6, _local5);
            var _local7:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local8:JLabel = new JLabel(String(m_item.xpYield));
            _local8.setFont(ASwingHelper.getBoldFont(21));
            _local8.setForeground(new ASColor(EmbeddedArt.brownTextColor, 1));
            var _local9:AssetPane = new AssetPane((new (SuppliesDialog.assetDict["star"])() as DisplayObject));
            _local7.appendAll(_local9, _local8);
            var _local10:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local11:JLabel = new JLabel(CardUtil.localizeTimeLeft(m_item.growTime));
            _local11.setFont(ASwingHelper.getBoldFont(16));
            _local11.setForeground(new ASColor(EmbeddedArt.brownTextColor, 1));
            var _local12:AssetPane = new AssetPane((new (SuppliesDialog.assetDict["truck"])() as DisplayObject));
            _local10.appendAll(_local12, _local11);
            _local1.appendAll(_local2, _local4, _local7, _local10);
            return (_local1);
        }
        override protected function scaleToFit(_arg1:DisplayObject):Number{
            var _local2:Number = 1;
            var _local3:Number = 1;
            var _local4:int = (this.m_containerHeight - 4);
            var _local5:int = (this.m_containerWidth - 4);
            if (_arg1.width > _local5){
                _local2 = (_local5 / _arg1.width);
            };
            if (_arg1.height > _local4){
                _local3 = (_local4 / _arg1.height);
            };
            return (Math.min(_local2, _local3));
        }
        private function buyItem(_arg1:MouseEvent):void{
            dispatchEvent(new DataItemEvent(DataItemEvent.MARKET_BUY, this.m_item, null, true));
        }
        override protected function initializeCell():void{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            var _local3:AssetPane = new AssetPane(m_itemIcon);
            ASwingHelper.prepare(_local3);
            _local1.append(_local3);
            ASwingHelper.prepare(_local1);
            _local2.append(_local1);
            ASwingHelper.prepare(_local2);
            this.m_itemIconHolder.append(_local2);
            ASwingHelper.prepare(this.m_itemIconHolder);
        }
        public function removeListeners():void{
            this.removeEventListener(MouseEvent.CLICK, this.buyItem);
        }
        private function onBuyClick(_arg1:MouseEvent):void{
            var _local2:int;
            if (Global.player.cash >= m_item.cash){
                _local2 = this.getIndex(this.m_itemCost);
                this.removeAt(_local2);
                this.m_itemCost = null;
                this.m_itemCost = new JLabel(((Global.player.inventory.getItemCountByName(m_item.name).toString() + "/") + this.m_amountNeeded));
                this.m_itemCost.setForeground(new ASColor(0xFFFFFF, 1));
                this.m_itemCost.setFont(ASwingHelper.getBoldFont(14));
                this.insert(_local2, this.m_itemCost);
            };
        }

    }
}//package Display.FactoryUI 
